pub trait Summary {
    fn summarize(&self) -> String {
        String::from("Reade more...")
    }
    fn summarize_author(&self) -> String; 
}
pub struct Weibo{
    pub username: String,
        content: String
}

impl Summary for Weibo {
   fn summarize(&self) -> String {
        format!("Content:{}", self.content)
    }
   fn summarize_author(&self) -> String {
       format!("@{}", self.username)
   }
}

//使用特征作为函数参数
pub fn notify(item: &impl Summary) {
    println!("Breaking news! {}", item.summarize());
}
//函数返回中的 impl trait
fn returns_summarizable() -> impl Summary {
    Weibo {
        username: String::from("sunface"),
        content: String::from(
            "m4 mac 太历害了，电脑再不会卡"
        )
    }
}
fn main() {
    let weibo = Weibo{username: String::from("Musk"), content: "I smell you!".to_string()};
    println!("{}, {}",weibo.summarize(), weibo.summarize_author());
    notify(&weibo);
    let wb_t = returns_summarizable();
    println!("{}, {}",wb_t.summarize_author(), wb_t.summarize());
}

